﻿using System;
using System.Collections.Generic;
using System.Text;
using Quanlynhasach.hethongluutru;
using Quanlynhasach.hethongxuly;
using System.Data;



namespace Quanlynhasach.hethongluutru
{
    class SachDAO
    {
        public static DataTable TraCuuSach(string tenSach)
        { 
                string sql; 
                sql = "Select MaSach, MaTheLoai, MaTacGia, TenSach, GiaBan, SoLuongTon From Sach "; 
    sql += " where TenSach like '%" + tenSach + "%'";  
                
                DataTable dt = database.ExcuQuery(sql);

                return dt;
        }
        public static DataTable LayDanhSachSach()
        {
            string sql;
            sql = "Select * from Sach";
            DataTable dt = database.ExcuQuery(sql);

            return dt;
        }
        public void ThemSach(SachDTO sDTO)
        {
            string sql;
            sql = "Insert into Sach(TenSach,MaTheLoai,MaTacGia,GiaBan,SoLuongTon) values ('" + sDTO.TenSach+ "','" + sDTO.MaTheLoai + "','" + sDTO.MaTacGia+"','" + sDTO.GiaBan+ "','"+sDTO.SoLuongTon+"')";
            database.ExcuNonQuery(sql);
        }
        public void XoaSach(SachDTO sDTO)
        {
            string sql;
            sql = "Delete From Sach Where MaSach =" + sDTO.MaSach+"";
            database.ExcuNonQuery(sql);
        }
        public void SuaSach(SachDTO sDTO)
        {
            string sql;
            sql = "Update Sach Set TenSach=('" + sDTO.TenSach + "'),MaTheLoai=('"+sDTO.MaTheLoai+"'),MaTacGia=('"+sDTO.MaTacGia+"'),GiaBan=('"+sDTO.GiaBan+"'),SoLuongTon=('"+sDTO.SoLuongTon+"')";
            sql += " Where MaSach = " + sDTO.MaSach+"";
            database.ExcuNonQuery(sql);
        }
        static public void UpdateSoLuongTon(SachDTO sDTO)
        {
            string sql = "update SACH set SoLuongTon=(" + sDTO.SoLuongTon + ") where MaSach = " + sDTO.MaSach + "";
            database.ExcuNonQuery(sql);
            
        }
    }
}
